
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

int auth()
{
	return 0;
}

/*
#include <sina_account.h>

#include <client.h>
#include <setting.h>

extern struct client_t g_client;
extern struct setting_t g_setting;

#define SINA_CN     "@sina.cn"
#define SINA_COM    "@sina.com"
#define SINA_COM_CN "@sina.com.cn"
#define SINA_VIP    "@vip.sina.com"
#define DEFAULT_TYPE 	"@sina.com"

#define TYPE_CN		1
#define TYPE_COM	2
#define TYPE_COM_CN	3
#define TYPE_VIP	4

#define IMAP4_ALLOW_FREE  0x00004000
#define IMAP4_ALLOW_VIP   0x00002000
#define VIP_IMAP_EXPIRED  0x00000001

#define FREE_IMAP_LEVEL    (0x1<<15)
#define FREE_IMAP_STEAL1   222
#define FREE_IMAP_STEAL2   223
#define FREE_IMAP_STEAL3   225
#define FREE_IMAP_ACTIVE   (0x1<<23)


int getmailtype()
{
	char *mail = g_client.user;

	char *p = strchr(mail, '@');
	if(p == NULL) {
		strcat(mail, DEFAULT_TYPE);
	} else if(strlen(p) == 1) {
		sprintf(p, DEFAULT_TYPE);
	}

	if(strcmp(p, SINA_COM) == 0) {
		return TYPE_COM;
	} else if(strcmp(p, SINA_CN) == 0) {
		return TYPE_CN;
	} else if(strcmp(p, SINA_VIP) == 0) {
		return TYPE_VIP;
	} else if(strcmp(p, SINA_COM_CN) == 0) {
		sprintf(p, SINA_COM);
		return TYPE_COM;
	} else {
		return -1;
	}

	return 0;
}

int auth()
{
	int mail_type = getmailtype();
	if(mail_type == -1) {
		return -1;
	}

	int idc   = 0;
	int port  = 143;  // default imap port

	BaseMailInfo info;
	long long uid = 0;
	long long status = 0;
	int  rc;
	int  count = 0;

	rc = sinamailAuthInfo(g_client.user, g_client.pass, &info, g_client.cliaddr, &uid, &status );
	if ( (rc == 1017) && count < 3 ) {
		uid = 0;
		status = 0;
		rc = sinamailAuthInfo( g_client.user, g_client.pass, &info, g_client.cliaddr, &uid, &status );
	}
	if ( RET_OK != rc ) {
		return -1;
	}

	unsigned long us = info.ulUserStat;

	if(strcmp(g_client.user, info.cMail) != 0) {
		if(us & FREE_IMAP_ACTIVE) {
			snprintf(g_client.user, sizeof(g_client.user)-1, "%s", info.cMail);
			mail_type = getmailtype();
		} else {
			return -1;
		}
	}

	if ((mail_type != TYPE_VIP && 0 != (us & IMAP4_ALLOW_FREE)) ||
			(mail_type == TYPE_VIP && 0 == (us & IMAP4_ALLOW_VIP) && !(us & VIP_IMAP_EXPIRED)) ) {
		return -1;
	}

	if((us & FREE_IMAP_LEVEL) && ( (status == FREE_IMAP_STEAL1) ||
				(status == FREE_IMAP_STEAL2) || (status == FREE_IMAP_STEAL3) )) {
		return -1;
	}

	switch ( mail_type ) {
		case TYPE_CN:
			idc   = (us >> 28) & 0x0F;
			//port  = (idc == 0) ? setting.free_tj : setting.free_gz;
			break;
		case TYPE_COM:
			if ( 0 == strcasecmp(info.cServerId, "sina.com.mda0") ) {
				idc  = 0;
				//port = setting.free_tj;
			}
			else if ( 0 == strcasecmp(info.cServerId, "sina.com.mda1") ) {
				idc  = 1;
				//port = setting.free_gz;
			}
			else {
				return -1;
			}
			break;
		case TYPE_VIP:
			if ( 0 == strcasecmp(info.cServerId, "vipmail0.mail.sina.com.cn") ) {
				idc  = 0;
				//port = setting.vip_tj;
			}
			else if ( 0 == strcasecmp(info.cServerId, "vipmail1.mail.sina.com.cn") ) {
				idc  = 1;
				//port = setting.vip_gz;
			}
			else if ( 0 == strcasecmp(info.cServerId, "vipmail2.mail.sina.com.cn") ) {
				idc  = 2;
				//port = setting.vip_tc;
			}
			else {
				return -1;
			}
			break;
		default:
			return -1;
	}

	snprintf(g_client.servaddr, sizeof(g_client.servaddr), "imap%d.%s", idc, g_setting.imapd_domain);
	g_client.servport = g_setting.imapd_port;

	return 0;
}

*/
